;;;; srfi-11.test --- exercise SRFI-11 let-values
;;;;
;;;; Copyright 2004, 2006 Free Software Foundation, Inc.
;;;;
;;;; This program is free software; you can redistribute it and/or modify
;;;; it under the terms of the GNU General Public License as published by
;;;; the Free Software Foundation; either version 2, or (at your option)
;;;; any later version.
;;;;
;;;; This program is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;;; GNU General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU General Public License
;;;; along with this software; see the file COPYING.  If not, write to
;;;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;;;; Boston, MA 02110-1301 USA

(define-module (test-suite test-srfi-11)
  #:use-module (test-suite lib)
  #:use-module (srfi srfi-11))


;;
;; let-values
;;

(with-test-prefix "let-values"

  (with-test-prefix "no exprs"

    (pass-if "no values"
      (let-values ()
	#t)))

  (with-test-prefix "one expr"

    (pass-if "no values"
      (let-values ((() (values)))
	#t))

    (pass-if "one value"
      (let-values (((x) (values 1)))
	(equal? x 1)))

    (pass-if "one value as rest"
      (let-values ((x (values 1)))
	(equal? x '(1))))

    (pass-if "two values"
      (let-values (((x y) (values 1 2)))
	(and (equal? x 1)
	     (equal? y 2)))))

  (with-test-prefix "two exprs"

    (pass-if "no values each"
      (let-values ((() (values))
		   (() (values)))
	#t))

    (pass-if "one value / no values"
      (let-values (((x) (values 1))
		   (() (values)))
	(equal? x 1)))

    (pass-if "one value each"
      (let-values (((x) (values 1))
		   ((y) (values 2)))
	(and (equal? x 1)
	     (equal? y 2))))

    (pass-if-exception "first binding invisible to second expr"
	'(unbound-variable . ".*")
      (let-values (((x) (values 1))
		   ((y) (values (1+ x))))
	#f))))

;;
;; let*-values
;;

(with-test-prefix "let*-values"

  (with-test-prefix "no exprs"

    (pass-if "no values"
      (let*-values ()
	#t)))

  (with-test-prefix "one expr"

    (pass-if "no values"
      (let*-values ((() (values)))
	#t))

    (pass-if "one value"
      (let*-values (((x) (values 1)))
	(equal? x 1)))

    (pass-if "one value as rest"
      (let-values ((x (values 1)))
	(equal? x '(1))))

    (pass-if "two values"
      (let*-values (((x y) (values 1 2)))
	(and (equal? x 1)
	     (equal? y 2)))))

  (with-test-prefix "two exprs"

    (pass-if "no values each"
      (let*-values ((() (values))
		    (() (values)))
	#t))

    (pass-if "one value / no values"
      (let*-values (((x) (values 1))
		    (() (values)))
	(equal? x 1)))

    (pass-if "one value each"
      (let*-values (((x) (values 1))
		    ((y) (values 2)))
	(and (equal? x 1)
	     (equal? y 2))))

    (pass-if "first binding visible to second expr"
      (let*-values (((x) (values 1))
		    ((y) (values (1+ x))))
	(and (equal? x 1)
	     (equal? y 2))))))
